!> TRANSFORM : Subroutines related to coordinate transformations
!! This module contains coordinate transformation subroutines for LACM
!! @author Dharhas Pothina
!! @created 20080213
!! @modified 20080421
!! @file lacm_transform.f90
module lacm_transform
	use lacm_globals
	implicit none
contains
	!> xy2riv : converts xy nodes to river coordinates
	!! @author Dharhas Pothina
	!! @param[in,out] mesh Structure containing mesh information
	!! @param[in] interp Type of interpolation. Presently only linear 
	subroutine xy2riv(mesh,interp)
		type (meshpt), dimension(:) :: mesh
		character (len=6) :: interp
		integer ii
	
		!! @todo add interp options. Presently only linear.
		select case(interp)	
			case default
				! set boundary node values
				mesh(1)%s=0
				mesh(1)%ds=0
				do ii=2,np
					! Calc dist between nodes
					mesh(ii)%ds=sqrt( (mesh(ii)%x-mesh(ii-1)%x)**2 + (mesh(ii)%y-mesh(ii-1)%y)**2 )
					! Accumulate distances to get distance along thalweg
					mesh(ii)%s = mesh(ii-1)%s + mesh(ii)%ds
					!write(*,*) "ii,mesh-s,mesh-ds",ii,mesh(ii)%s,mesh(ii)%ds					
				end do
		end select	
	end subroutine xy2riv

end module lacm_transform